﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;//MD5加密需引入的命名空间
namespace YmSoft.Kblog.Utility
{
    /// <summary>
    /// Md5加密类（不可逆转）
    /// </summary>
    public class GetMd5
    {
        public GetMd5()
        {

        }
        

    /// <summary>
    /// MD5加密
    /// </summary>
    /// <param name="strPwd">被加密的字符串</param>
    /// <returns>返回加密后的字符串</returns>

    public string MD5(string strPwd)
    {
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] data = System.Text.Encoding.Default.GetBytes(strPwd);//将字符编码为一个字节序列
        byte[] md5data = md5.ComputeHash(data);//计算data字节数组的哈希值
        md5.Clear();
        string str = "";
        for (int i = 0; i <md5data.Length-1; i++)
        {
            str += md5data[i].ToString("x").PadLeft(2,'0');
        }
        return str;
    }
    }
}
